package cn.bdqn.or.controller.xingcontorller;

import cn.bdqn.or.pojo.xingpojo.User;
import cn.bdqn.or.service.xingservice.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/User")
public class UserController {
    @RequestMapping("/selectUser")
    public String selectUser(HttpServletRequest request,Model model){
        User user = new User();
        request.setAttribute("user",user);
       return "user_list";
    }
    @RequestMapping("/getTotal")
    public int getTotal(@Param("total") int total){

        return total;
    }
    @RequestMapping("/findAll")
    public String findAll(HttpServletRequest request,
                          @Param("memberName") String memberName,Model model){
String memberName1 = request.getParameter("memberName");
UserService userService = new UserService();
userService.findAll(memberName1);
        return "user_list";
    }
    @RequestMapping("/findById")
    public String findById(HttpServletRequest request,@Param("memberId") Integer memberId,Model model){
  User user = new User();
  Integer memberId1 = Integer.parseInt(request.getParameter("memberId"));
       UserService userService = new UserService();
       userService.findById(memberId1);
        return "user_list";
    }
    @RequestMapping("/addUser")
    public String addUser(HttpServletRequest request,Model model){
        User user = new User();
        user.setMemberName(request.getParameter("memberName"));
        user.setMemberRealName(request.getParameter("MemberRealName"));
        user.setSex(request.getParameter("sex"));
        user.setFixedTelephone(request.getParameter("fixedTelephone"));
        user.setPhone(request.getParameter("phone"));
        user.setEmail(request.getParameter("Email"));
        user.setAddress(request.getParameter("Address"));
        user.setMemberStatus(request.getParameter("MemberStatus"));
      UserService userService = new UserService();
      userService.addUser((cn.bdqn.or.dao.xingdao.User) user);
      return "user_list";
    }
    @RequestMapping("/updateUser")
    public String updateUser(HttpServletRequest request,@Param("memberId") Integer memberId,Model model){
     User user = new User();
     Integer memberId2 = Integer.parseInt(request.getParameter("memberId"));
        user.setMemberName(request.getParameter("memberName"));
        user.setMemberRealName(request.getParameter("MemberRealName"));
        user.setSex(request.getParameter("sex"));
        user.setFixedTelephone(request.getParameter("fixedTelephone"));
        user.setPhone(request.getParameter("phone"));
        user.setEmail(request.getParameter("Email"));
        user.setAddress(request.getParameter("Address"));
        user.setMemberStatus(request.getParameter("MemberStatus"));
        UserService userService = new UserService();
        userService.updateUser((cn.bdqn.or.dao.xingdao.User) user,memberId2);
        return "user_list";
    }
    @RequestMapping("/deleteUser")
    public String deleteUser(HttpServletRequest request,@Param("memberId") Integer memberId,Model model){
        Integer memberId2 = Integer.parseInt(request.getParameter("memberId"));
        UserService userService = new UserService();
        userService.deleteUser(memberId2);
        return "user_list";
    }
}
